package com.xxxx.server.controller;

import com.xxxx.server.mapper.DepartmentMapper;
import com.xxxx.server.pojo.Department;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 部门管理模块
 */
@RestController
@RequestMapping("/system/basic")
public class SystemDepartmentController {

    @Resource
    private IDepartmentService iDepartmentService;

    @Resource
    private DepartmentMapper departmentMapper;

    /**
     * 部门管理初始化查询
     * @return
     */
    @GetMapping("/department")
    @ApiOperation(value = "部门管理初始化查询")

    public List<Department> getSystemDepartment() {
        return iDepartmentService.selectSystemDepartment();

    }
    /**
     * 添加管理部门
     * @param department
     * @return
     */
    @PostMapping("/department")
    @ApiOperation(value = "添加管理部门")
    public RespBean addSystemDepartmentController(@RequestBody Department department) {
        if (departmentMapper.insert(department) == 1) {
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    /**
     * 删除管理部门
     * @param id
     * @return
     */
    @DeleteMapping("/department/{id}")
    @ApiOperation(value = "管理部门删除")
    public RespBean deleteSystemDepartmentController(@PathVariable Integer id) {
        if (departmentMapper.deleteById(id) == 1) {
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }
}
